﻿using System.Xml;

using pt = System.UInt32;

namespace RDLC
{
   public class RDLRectangle : ReportItem
   {

      public bool? PageBreakAtStart
      {
         get { return _PageBreakAtStart; }
         set
         {
            if(!_PageBreakAtStart.HasValue)
               _PageBreakAtStart = new bool();
            _PageBreakAtStart = value;
         }
      }
      private bool? _PageBreakAtStart;

      public bool? PageBreakAtEnd
      {
         get { return _PageBreakAtEnd; }
         set
         {
            if(!_PageBreakAtEnd.HasValue)
               _PageBreakAtEnd = new bool();
            _PageBreakAtEnd = value;
         }
      }
      private bool? _PageBreakAtEnd;

      public RDLReportItems ReportItems = new RDLReportItems(); // Optional

      public string Bookmark; // Optional
      public string LinkToChild; // Optional
      public string RepeatWith; // Optional
      public string ToolTip; // Optional

      public RDLRectangle(string name, RDLPosition position, RDLStyle style) 
         : base(name, "Rectangle", position, style)
      {
      }

      protected override void WriteDetails(XmlTextWriter writer)
      {
         if(PageBreakAtEnd.HasValue)
            writer.WriteElementString("PageBreakAtEnd", PageBreakAtEnd.Value.ToString());

         if(PageBreakAtStart.HasValue)
            writer.WriteElementString("PageBreakAtStart", PageBreakAtStart.Value.ToString());

         ReportItems.Write(writer);

         if(!string.IsNullOrEmpty(ToolTip))
            writer.WriteElementString("ToolTip", ToolTip);

         if(!string.IsNullOrEmpty(Bookmark))
            writer.WriteElementString("Bookmark", Bookmark);

         if(!string.IsNullOrEmpty(LinkToChild))
            writer.WriteElementString("LinkToChild", LinkToChild);

         if(!string.IsNullOrEmpty(RepeatWith))
            writer.WriteElementString("RepeatWith", RepeatWith);
      }
   }

   public class RectangleStyle : RDLStyle
   {
      public RDLColor? BackgroundColor
      {
         get { return _BackgroundColor; }
         set
         {
            if(!_BackgroundColor.HasValue)
               _BackgroundColor = new RDLColor();
            _BackgroundColor = value;
         }
      }
      private RDLColor? _BackgroundColor;
      public string BackgroundColorExpression;

      public RDLImage BackgroundImage;

      public RectangleStyle(RDLBorderColor borderColor, RDLBorderStyle borderStyle, RDLBorderWidth borderWidth)
         : base(borderColor, borderStyle, borderWidth)
      {
      }

      public RectangleStyle()
      {

      }

      protected override void WriteDetails(XmlTextWriter writer)
      {
         if(BackgroundColor.HasValue)
            writer.WriteElementString("BackgroundColor", BackgroundColor.Value.ToString());
         else if(BackgroundColorExpression != null)
            writer.WriteElementString("BackgroundColor", BackgroundColorExpression);

         if(BackgroundImage != null)
            BackgroundImage.Write(writer);
      }
   }
}
